{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Please  Introduce yourself: 222\n",
      "\u001b[1;33mWe asked him to introduce himself first.He said \" 222 .\"\u001b[3;31m\n",
      "这行是上一行结尾的颜色输出效果 \n"
     ]
    }
   ],
   "source": [
    "info = input(\"Please  Introduce yourself: \")\n",
    "print('\\033[1;33mWe asked him to introduce himself first.He said \\\" %s .\\\"\\033[3;31m' %info)\n",
    "print('这行是上一行结尾的颜色输出效果 ')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 具体格式\n",
    "\n",
    "设置颜色开始 ：`\\033[显示方式;前景色;背景色m`\n",
    "\n",
    "注：';'前后的三个参数：显示方式，前景色，背景色是可选参数，可以只写其中的某一个或者某两个；由于表示三个参数不同含义的数值都是唯一没有重复的，所以三个参数的书写先后顺序没有固定要求，系统都可识别；\n",
    "建议按照默认的格式规范书写.\n",
    "\n",
    "|显示方式| 意义\n",
    "|:----|:----:|\n",
    "0|默认\n",
    "1|高亮\n",
    "22|非高亮\n",
    "4|下划线\n",
    "24|去下划线\n",
    "5|闪烁\n",
    "25|非闪烁\n",
    "7|反显\n",
    "27|非反显\n",
    "8|不可见\n",
    "28|可见\n",
    "\n",
    "|前景色|颜色|\n",
    "|:---|:--:|\n",
    "30|黑色|\n",
    "31|红色|\n",
    "32|绿色\n",
    "33|黄色\n",
    "34|蓝色\n",
    "35|洋红\n",
    "36|青色\n",
    "37|白色\n",
    "\n",
    "\n",
    "|  背景色  | 颜色|\n",
    "|:----|:----:|\n",
    "|40|黑色|\n",
    " 41 | 红色|\n",
    " 42 | 绿色|\n",
    " 43 | 黃色|\n",
    " 44 | 蓝色|\n",
    " 45 | 洋红|\n",
    " 46 | 青色|\n",
    " 47 | 白色|\n",
    " \n",
    "\n",
    " \n",
    "例：\n",
    "\n",
    "- \\033[1;32;41m  \n",
    "  - 1-高亮显示\n",
    "  - 32-前景色绿色 \n",
    "  - 40-背景色红色---\n",
    "\n",
    "- \\033[0m \n",
    "  - 采用终端默认设置，即缺省颜色"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[1;31;40m\n",
      "**************************************************\n",
      "\u001b[7;31m错误次数超限，用户已被永久锁定，请联系管理员！\u001b[1;31;40m\n",
      "**************************************************\n",
      "\u001b[0m\n",
      "aaaa\n"
     ]
    }
   ],
   "source": [
    "#-*- coding:utf-8 -*-\n",
    "print('\\033[1;31;40m')     #下一目标输出背景为黑色，颜色红色高亮显示\n",
    "print('*' * 50)\n",
    "print('\\033[7;31m错误次数超限，用户已被永久锁定，请联系管理员！\\033[1;31;40m')  #字体颜色红色反白处理\n",
    "print('*' * 50)\n",
    "print('\\033[0m') #恢复默认\n",
    "print('aaaa')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[0m这是显示方式0\n",
      "\u001b[1m这是显示方式1\n",
      "\u001b[4m这是显示方式4\n",
      "\u001b[5m这是显示方式5\n",
      "\u001b[7m这是显示方式7\n",
      "\u001b[8m这是显示方式8\n",
      "\u001b[30m这是前景色0\n",
      "\u001b[31m这是前景色1\n",
      "\u001b[32m这是前景色2\n",
      "\u001b[33m这是前景色3\n",
      "\u001b[34m这是前景色4\n",
      "\u001b[35m这是前景色5\n",
      "\u001b[36m这是前景色6\n",
      "\u001b[37m这是前景色7\n",
      "\u001b[40m这是背景色0\n",
      "\u001b[41m这是背景色1\n",
      "\u001b[42m这是背景色2\n",
      "\u001b[43m这是背景色3\n",
      "\u001b[44m这是背景色4\n",
      "\u001b[45m这是背景色5\n",
      "\u001b[46m这是背景色6\n",
      "\u001b[47m这是背景色7\n"
     ]
    }
   ],
   "source": [
    "print('\\033[0m这是显示方式0')\n",
    "print('\\033[1m这是显示方式1')\n",
    "print('\\033[4m这是显示方式4')\n",
    "print('\\033[5m这是显示方式5')\n",
    "print('\\033[7m这是显示方式7')\n",
    "print('\\033[8m这是显示方式8')\n",
    "print('\\033[30m这是前景色0')\n",
    "print('\\033[31m这是前景色1')\n",
    "print('\\033[32m这是前景色2')\n",
    "print('\\033[33m这是前景色3')\n",
    "print('\\033[34m这是前景色4')\n",
    "print('\\033[35m这是前景色5')\n",
    "print('\\033[36m这是前景色6')\n",
    "print('\\033[37m这是前景色7')\n",
    "print('\\033[40m这是背景色0')\n",
    "print('\\033[41m这是背景色1')\n",
    "print('\\033[42m这是背景色2')\n",
    "print('\\033[43m这是背景色3')\n",
    "print('\\033[44m这是背景色4')\n",
    "print('\\033[45m这是背景色5')\n",
    "print('\\033[46m这是背景色6')\n",
    "print('\\033[47m这是背景色7')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "\n",
    "# --------------------------------------------------------------------------\n",
    "# Colored Output in Console\n",
    "# --------------------------------------------------------------------------\n",
    "BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(90, 98)\n",
    "\n",
    "\n",
    "def COLOR_STR(msg, color=WHITE):\n",
    "    return '\\033[%dm%s\\033[0m' % (color, msg)\n",
    "\n",
    "\n",
    "def PRINT(msg, color=WHITE):\n",
    "    sys.stdout.write(COLOR_STR(msg, color) + '\\n')\n",
    "\n",
    "for i in range(90, 98):    \n",
    "    PRINT('hello world--%d'%i, i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
